var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
var app = getApp();

Page({
  data: {
     // 默认选中菜单
     currentTab: 0,
     index: 0,
     goodsId: '',
    categoryFilter: false,
    clientGoodsShelves: [],
    goodsImgList: [],
    categoryId: 0
  },
  getData: function () {
    let that = this;
    that.getClientOrderConfirm();
  },
  getClientOrderConfirm() {
    var that = this;
    console.log('获取订单详情')
    util.request(api.ClientGoodsShelves, {goodsId: that.data.goodsId })
      .then(function (res) {
        if (res.errno === 0) {
          that.setData({
            clientGoodsShelves: res.data,
            goodsImgList: res.data.imgList
          });
        }
      });
  },
  goConfirm: function (e) {
   //确认
   let that = this;
   var orderNo = e.target.dataset.orderNo;
   console.log("orderNo:"+orderNo);
   wx.switchTab({
    url: '../cGoodsShelvesUploadImg/cGoodsShelvesUploadImg',   //注意switchTab只能跳转到带有tab的页面，不能跳转到不带tab的页面
})
  },
  goCancel: function (e) {
   //取消
   let that = this;
   var orderNo = e.target.dataset.orderNo;
   console.log("orderNo:"+orderNo);
   wx.showModal({
    title: '提示',
    content: '取消此订单?',
    success: function (res) {
      if (res.confirm) {
        
        util.request(api.ClientOrderGoCancel, { orderNo: orderNo }).then(function (res) {
          if (res.errno === 0) {
            wx.showToast({
              title: '已取消',
              icon: 'success',
              duration: 2000
            });
            that.getClientOrderConfirm();
          }
        });

        console.log('用户已取消订单');
      } else if (res.cancel) {
        console.log('用户点击取消');
      }
    }
  })
  },
  onShelfOffShelf: function (e) {
    //取消
    let that = this;
    var onOff = e.target.dataset.onOff;
    var onOffStr = (onOff=='1'?'上架':'下架')+"此商品?";
    console.log("onOff:"+onOff);
    wx.showModal({
     title: '提示',
     content: onOffStr,
     success: function (res) {
       if (res.confirm) {
         
         util.request(api.ClientGoodsShelvesOnOff, { goodsId: that.data.goodsId,onOff: onOff }).then(function (res) {
           if (res.errno === 0) {
             wx.showToast({
               title: '操作成功',
               icon: 'success',
               duration: 2000
             });
             that.getClientOrderConfirm();
           }
         });
 
         console.log('上下架完成');
       } else if (res.cancel) {
         console.log('用户取消上下架操作');
       }
     }
   })
   },
  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
    var that = this
    that.setData({
      goodsId: options.goodsId
    })
    console.log('goodsId=======goodsId======'+that.data.goodsId);
    that.getData();
  },
  onReady: function () {
    // 页面渲染完成
  },
  onShow: function () {
    // 页面显示

  },
  onHide: function () {
    // 页面隐藏

  },
  onUnload: function () {
    // 页面关闭

  }
})